<!--
  @author:  long
  @date:    2023/3/31
  @file:    xx
  @require:
-->
<template>
  <div class="px-20 pb-10">
    <!-- 基于element-plus创建一个表单，包含字段 一级指标，二级指标，考核频率，指标说明及工作内容、工作要求，指标单位，指标值，考核评分标准，分值权重，考核人，被考核人部门，被考核人姓名，被考核人职务，被考核人岗位，技分方式  -->
    <el-form
      label-width="150px"
      class="mt-4"
      :model="form"
      ref="formRef"
      destroy-on-close
      :rules="rules"
    >
      <TitleName
        title="指标内容"
        class="py-2"
        icon="i-carbon-bookmark-filled"
      ></TitleName>

      <el-row>
        <el-col :span="12">
          <el-form-item label="一级指标：" prop="firstLevel">
            <el-input
              clearable
              v-model="form.firstLevel"
              placeholder="请输入一级指标"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="二级指标：">
            <el-input
              clearable
              v-model="form.secondLevel"
              placeholder="请输入二级指标"
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="分值权重：" prop="score">
            <el-input
              clearable
              v-model="form.score"
              placeholder="请输入或选择分值权重"
              @input="scoreSelect = ''"
            >
              <template #append>
                <el-select
                  v-model="scoreSelect"
                  clearable
                  style="width: 100px"
                  placeholder=" "
                  @change="handleScoreSelect"
                >
                  <el-option
                    v-for="(dict, index) in scoreSelectOptions"
                    :key="index"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="form.scoreMethod != '1'">
          <el-form-item label="指标值：" prop="targetValue">
            <div class="flex items-center w-full">
              <div class="flex items-center w-full">
                <el-input
                  clearable
                  class="w-full"
                  v-model="form.targetValue"
                  placeholder="请输入指标值"
                  @input="targetValueInput"
                >
                  <template #append>
                    <el-select
                      v-model="form.unit"
                      clearable
                      style="width: 80px"
                      placeholder="请选择指标单位"
                    >
                      <el-option
                        v-for="(dict, index) in indicator_unit"
                        :key="index"
                        :label="dict.label"
                        :value="dict.value"
                      ></el-option>
                    </el-select>
                  </template>
                </el-input>
              </div>
              <el-tooltip
                effect="dark"
                content="仅经营类考核填写此列"
                placement="top"
              >
                <el-icon class="ml-1" style="position: absolute; right: -18px"
                  ><InfoFilled
                /></el-icon>
              </el-tooltip>
            </div>
          </el-form-item>
        </el-col>
        <!--        <el-col :span="12">-->
        <!--          <el-form-item label="指标单位：">-->
        <!--            <el-select-->
        <!--              v-model="form.unit"-->
        <!--              clearable-->
        <!--              class="w-full"-->
        <!--              placeholder="请选择指标单位"-->
        <!--            >-->
        <!--              <el-option-->
        <!--                v-for="(dict, index) in indicator_unit"-->
        <!--                :key="index"-->
        <!--                :label="dict.label"-->
        <!--                :value="dict.value"-->
        <!--              ></el-option>-->
        <!--            </el-select>-->
        <!--          </el-form-item>-->
        <!--        </el-col>-->

        <el-col :span="24">
          <el-form-item label="指标说明及工作内容、工作要求：" prop="content">
            <el-input
              type="textarea"
              rows="3"
              clearable
              placeholder="请输入指标说明及工作内容、工作要求"
              v-model="form.content"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col v-if="form.scoreMethod == '2'" :span="24">
          <el-form-item label="完成率计分方案：" prop="scoreStandardCode">
            <el-select
              v-model="form.scoreStandardCode"
              class="w-full"
              placeholder="请选择考核评分标准方案"
              @change="scoreStandardCodeChange"
            >
              <el-option
                v-for="(dict, index) in scoring_scheme"
                :key="index"
                :label="dict.label + ' —— ' + dict.remark"
                :value="dict.value"
              >
                <template #default>
                  <div>
                    <span>{{ dict.label }}</span>
                    <span> —— {{ dict.remark }}</span>
                  </div>
                </template>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            label="考核评分标准："
            prop="scoreStandard"
            v-if="form.scoreMethod != '2'"
          >
            <el-input
              type="textarea"
              rows="3"
              clearable
              class="w-full"
              :disabled="form.scoreMethod == '2'"
              v-model="form.scoreStandard"
              placeholder="请输入考核评分标准"
            ></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="考核人：">
            <div class="flex flex-col w-full">
              <div class="mb-2">
                <el-button type="primary" @click="selectAssessorUser"
                  >选择</el-button
                >
              </div>
              <div>
                <template v-if="assessorUserObj.length > 0">
                  <el-row v-for="(item, index) in assessorUserObj" :key="index">
                    <el-col :span="2">{{ item.label }}：</el-col>
                    <el-col :span="21">
                      <el-tag
                        v-for="tag in item.selectData"
                        :key="tag.itemValue"
                        class="mr-2 mb-2"
                        :type="tagType[index % 5]"
                      >
                        {{ tag.itemLabel }}
                      </el-tag>
                    </el-col>
                  </el-row>
                </template>
              </div>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="被考核人：">
            <div class="flex flex-col w-full">
              <div class="mb-2">
                <el-button type="primary" @click="selectAppraiserUser"
                  >选择</el-button
                >
              </div>
              <div>
                <template v-if="appraiserUserObj.length > 0">
                  <el-row
                    v-for="(item, index) in appraiserUserObj"
                    :key="index"
                  >
                    <el-col :span="2">{{ item.label }}：</el-col>
                    <el-col :span="21">
                      <el-tag
                        v-for="tag in item.selectData"
                        :key="tag.itemValue"
                        class="mr-2 mb-2"
                        :type="tagType[index % 5]"
                      >
                        {{ tag.itemLabel }}
                      </el-tag>
                    </el-col>
                  </el-row>
                </template>
              </div>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <TitleName title="评分" icon="i-carbon-bookmark-filled"></TitleName>

      <el-row>
        <el-col :span="12">
          <el-form-item label="计分方式：" prop="scoreMethod">
            <el-select
              v-model="form.scoreMethod"
              class="w-full"
              placeholder="请选择计分方式"
              :disabled="scoreMethodDisabled"
              @change="handleScoreMethodChange"
            >
              <el-option
                v-for="(dict, index) in scoring_method"
                :key="index"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="考核频率：" prop="frequency">
            <el-radio-group v-model="form.frequency">
              <el-radio
                :label="dict.value"
                v-for="(dict, index) in examine_frequency"
                :key="index"
                >{{ dict.label }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="form.scoreMethod == '3'">
          <el-form-item label="基础分：" prop="basicScore">
            <el-input-number
              v-model="form.basicScore"
              :min="0"
            ></el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="24" class="text-right">
          <el-button type="primary" @click="handleIndicatorSave"
            >保存</el-button
          >
          <el-button @click="dialogClose">取消</el-button>
        </el-col>
      </el-row>
    </el-form>
    <!--  select or tree 结构组件  -->
    <select-or-tree-dialog
      :dialog-param="selectOrTreeDialogParam"
      :tabsOptionsData="tabsOptionsData"
      @handleConfirm="handleConfirm"
    />
  </div>
</template>

<script setup name="AddOrUpdateIndicator">
// 通用数据store
import useCommonStore from '@/store/modules/common'
import { getCurrentInstance } from 'vue'
import { listDept } from '@/api/system/dept'
import { saveBizofficeconfInfo } from '@/api/officeManage/indicator'
import useUserStore from '@/store/modules/user'

const commonStore = useCommonStore()
const { proxy } = getCurrentInstance()
const emits = defineEmits(['dialogClose'])
const userStore = useUserStore()
const props = defineProps({
  // 1:新增 2:修改
  indicatorInfo: {
    type: String || Object,
    default: () => {
      return ''
    }
  }
})

const { scoring_method, indicator_unit, examine_frequency, scoring_scheme } =
  proxy.useDict(
    'scoring_method',
    'indicator_unit',
    'examine_frequency',
    'scoring_scheme'
  )
const data = reactive({
  form: {
    id: '',
    firstLevel: '',
    secondLevel: '',
    frequency: '0',
    content: '',
    unit: '1',
    targetValue: '',
    score: '',
    scoreMethod: '',
    scoreStandard: '',
    basicScore: 0,
    scoreStandardCode: ''
  },
  rules: {
    firstLevel: [
      { required: true, message: '请输入一级指标', trigger: 'blur' }
    ],
    frequency: [
      { required: true, message: '请选择考核频率', trigger: 'change' }
    ],
    content: [
      {
        required: true,
        message: '请输入指标说明及工作内容、工作要求',
        trigger: 'blur'
      }
    ],
    scoreMethod: [
      {
        required: true,
        message: '请选择计分方式',
        trigger: 'change'
      }
    ],
    // 考核评分标准
    scoreStandard: [
      {
        required: true,
        message: '请输入考核评分标准',
        trigger: 'blur'
      }
    ],
    // 考核评分标准编码
    scoreStandardCode: [
      {
        required: true,
        message: '请选择考核评分标准编码',
        trigger: 'change'
      }
    ],

    // 指标值
    score: [
      {
        required: true,
        message: '请输入或选择分值权重',
        trigger: 'blur'
      }
    ],
    // 基础分
    basicScore: [
      {
        required: true,
        message: '请输入基础分',
        trigger: 'blur'
      }
    ]
    // targetValue: [
    //   {
    //     required: true,
    //     message: '请输入指标',
    //     trigger: 'blur'
    //   }
    // ]
  },
  selectOrTreeDialogParam: {},
  tabsOptionsData: [],
  postOptions: [], //岗位
  selectOptionObj: {}, // select
  deptData: [],
  tagType: {
    1: 'success',
    2: 'warning',
    3: 'danger',
    4: 'info',
    5: ''
  },
  confirmType: ''
})

const {
  form,
  deptData,
  selectOptionObj,
  postOptions,
  rules,
  selectOrTreeDialogParam,
  tabsOptionsData,
  tagType,
  confirmType
} = toRefs(data)

//缴销考核标准方案详情
const planDetails = ref('')

// 考核人对象数组
const assessorUserObj = ref([])
// 被考核人对象数组
const appraiserUserObj = ref([])
//  分值权重选择
const scoreSelect = ref('')
const scoreMethodDisabled = ref(false)
const scoreSelectOptions = [
  { label: '加分项', value: '加分项' },
  { label: '加/减分项', value: '加/减分项' },
  { label: '减分项', value: '减分项' }
]
const dataTypeObj = {
  dept: {
    label: '部门',
    name: 'dept',
    selectData: []
  },
  person: {
    label: '人员列表',
    name: 'person',
    selectData: []
  },
  post: {
    label: '岗位',
    name: 'post',
    selectData: []
  },
  duties: {
    label: '职务',
    name: 'duties',
    selectData: []
  }
}

onMounted(() => {
  if (props.indicatorInfo !== '') {
    getInfo()
  }
})

/**
 * 指标值input事件
 */
const targetValueInput = val => {
  form.value.scoreMethod = val == '' ? '' : '2'
  scoreMethodDisabled.value = val == '' ? false : true
}

/**
 * 计分方式change事件
 */
const handleScoreMethodChange = val => {
  if (val != '1' && isNaN(form.value.score * 1)) {
    form.value.score = ''
    scoreSelect.value = ''
  }
}

/**
 * 分值权重选项选择
 */
const handleScoreSelect = val => {
  console.info('13', val)

  form.value.score = val
  form.value.scoreMethod = val == '' ? '' : '1'
  scoreMethodDisabled.value = val == '' ? false : true
}

/**
 * 绩效考核评分标准方案code
 */
const scoreStandardCodeChange = val => {
  console.info('scoring_scheme', scoring_scheme.value)
  form.value.scoreStandard = scoring_scheme.value.find(
    item => item.value == val
  ).remark
}

/**
 *根据info获取ids和names
 */
const getIdsAndNamesByInfo = (type, ids, names, data) => {
  if (ids != '' && ids != null) {
    let obj = {}
    let idsArr = ids.split(',')
    let namesArr = names.split(',')
    obj = JSON.parse(JSON.stringify(dataTypeObj[type]))
    idsArr.forEach((item, index) => {
      let o = {
        itemValue: item,
        itemLabel: namesArr[index]
      }
      if (type == 'person') {
        o.uuid = `U${item}`
      }
      obj.selectData.push(o)
    })
    data.push(obj)
  }
}

/**
 * @description: 获取指标详情
 */
const getInfo = () => {
  let info = props.indicatorInfo
  Object.keys(form.value).forEach(key => {
    form.value[key] = info[key]
  })

  console.info('京东卡京东卡萨克的')
  // 被考核人
  getIdsAndNamesByInfo(
    'dept',
    info.appraiseeDept,
    info.appraiseeDeptName,
    appraiserUserObj.value
  )
  getIdsAndNamesByInfo(
    'duties',
    info.appraiseeDuties,
    info.appraiseeDutiesName,
    appraiserUserObj.value
  )
  getIdsAndNamesByInfo(
    'post',
    info.appraiseePost,
    info.appraiseePostName,
    appraiserUserObj.value
  )
  getIdsAndNamesByInfo(
    'person',
    info.appraiseeUser,
    info.appraiseeUserName,
    appraiserUserObj.value
  )
  //考核人
  getIdsAndNamesByInfo(
    'dept',
    info.assessorDept,
    info.assessorDeptName,
    assessorUserObj.value
  )
  getIdsAndNamesByInfo(
    'duties',
    info.assessorDuties,
    info.assessorDutiesName,
    assessorUserObj.value
  )
  getIdsAndNamesByInfo(
    'post',
    info.assessorPost,
    info.assessorPostName,
    assessorUserObj.value
  )
  getIdsAndNamesByInfo(
    'person',
    info.assessorUser,
    info.assessorUserName,
    assessorUserObj.value
  )
}

/**
 * 设置selectData
 */
const setSelectDataByInfo = (type, data) => {
  selectOptionObj.value[type] = data
}
/**
 * 获取岗位数据
 */
const getPostData = async () => {
  const res = await commonStore.getPostData()
  postOptions.value = res
}
/**
 * 获取部门列表数据
 */
const getDeptList = () => {
  listDept().then(res => {
    deptData.value = proxy.handleTree(res.data, 'deptId')
  })
}

/**
 * @description: 选择考核人
 */
const selectAssessorUser = () => {
  // 设置confirmType显示提交类型
  confirmType.value = 'assessorUser'
  //   tabs配置数组
  tabsOptionsData.value = [
    {
      label: '部门', //tab的label
      name: 'dept', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'dept', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'deptId', //节点的key
        defaultCheckedKeys: [], //默认选中的节点
        treeLabelName: 'deptName' //树节点的label
      }
    },
    {
      label: '人员列表', //tab的label
      name: 'person', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'person', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'uuid', //节点的key
        defaultCheckedKeys: [] //默认选中的节点
      }
    },
    {
      label: '岗位', //tab的label
      name: 'post', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'post', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'postId', //节点的key
        defaultCheckedKeys: [], //默认选中的节点
        treeLabelName: 'postName' //树节点的label
      }
    },
    {
      label: '职务', //tab的label
      name: 'duties', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'duties', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'value', //节点的key
        defaultCheckedKeys: [], //默认选中的节点
        treeLabelName: 'label' //树节点的label
      }
    }
  ]
  // 如果考核人对象数组有值
  if (assessorUserObj.value.length > 0) {
    //assessorUserObj,用find查找tabsOptionsData中name等于assessorUserObj的name的对象
    //将对象的componentOptions.defaultCheckedKeys设置为考核人对象数组中的selectData的itemValue集合
    //componentOptions的selectData等于assessorUserObj中的selectData
    assessorUserObj.value.forEach(item => {
      const obj = tabsOptionsData.value.find(tab => tab.name === item.name)
      obj.componentOptions.defaultCheckedKeys = item.selectData.map(
        item => item.itemValue
      )
      obj.componentOptions.selectData = item.selectData
    })
  }

  proxy.$nextTick(() => {
    // 弹窗标题
    selectOrTreeDialogParam.value.title = '考核人'
    // 弹窗是否发开
    selectOrTreeDialogParam.value.isDialog = true
    //  是否多选，如果结果要为单选，则组件componentOptions.multiple设置为false
    selectOrTreeDialogParam.value.resultMultiple = true
  })
}

/**
 * @description: 选择被考核人
 */
const selectAppraiserUser = () => {
  // 设置confirmType显示提交类型
  confirmType.value = 'appraiserUser'
  //   tabs配置数组
  tabsOptionsData.value = [
    {
      label: '部门', //tab的label
      name: 'dept', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'dept', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'deptId', //节点的key
        defaultCheckedKeys: [], //默认选中的节点
        treeLabelName: 'deptName' //树节点的label
      }
    },
    {
      label: '人员', //tab的label
      name: 'person', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'person', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'uuid', //节点的key
        defaultCheckedKeys: [] //默认选中的节点
      }
    },
    {
      label: '岗位', //tab的label
      name: 'post', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'post', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'postId', //节点的key
        defaultCheckedKeys: [], //默认选中的节点
        treeLabelName: 'postName' //树节点的label
      }
    },
    {
      label: '职务', //tab的label
      name: 'duties', //tab的name
      component: 'CustomTree', //tab的组件
      componentOptions: {
        //组件的配置
        dataType: 'duties', //数据类型
        multiple: true, //是否多选
        checkStrictly: false, //是否严格的父子关联
        nodeKey: 'value', //节点的key
        defaultCheckedKeys: [], //默认选中的节点
        treeLabelName: 'label' //树节点的label
      }
    }
  ]
  // 如果考核人对象数组有值
  if (appraiserUserObj.value.length > 0) {
    //遍历appraiserUserObj,用find查找tabsOptionsData中name等于appraiserUserObj的name的对象
    //将对象的componentOptions.defaultCheckedKeys设置为考核人对象数组中的selectData的itemValue集合
    //componentOptions的selectData等于appraiserUserObj中的selectData
    appraiserUserObj.value.forEach(item => {
      const obj = tabsOptionsData.value.find(tab => tab.name === item.name)
      obj.componentOptions.defaultCheckedKeys = item.selectData.map(
        item => item.itemValue
      )
      obj.componentOptions.selectData = item.selectData
    })
  }

  proxy.$nextTick(() => {
    // 弹窗标题
    selectOrTreeDialogParam.value.title = '被考核人'
    // 弹窗是否发开
    selectOrTreeDialogParam.value.isDialog = true
    //  是否多选
    selectOrTreeDialogParam.value.resultMultiple = true
  })
}

/**
 * 考核人弹窗确定按钮
 */
const handleConfirm = result => {
  console.info('result', result)
  // 如果confirmType为assessorUser
  if (confirmType.value === 'assessorUser') {
    // 设置考核人对象数组
    assessorUserObj.value = result
  } else {
    // 设置被考核人对象数组
    appraiserUserObj.value = result
  }
}

const getValueByParams = (data, param, type) => {
  let result = ''

  let obj = data.find(item => item.name == param)
  if (obj) {
    if (type == 'ids') {
      result = obj.selectData
        .map(item => {
          return item.itemValue
        })
        .join(',')
    }
    if (type == 'labels') {
      result = obj.selectData
        .map(item => {
          return item.itemLabel
        })
        .join(',')
    }
  }

  return result
}

/**
 * 获取提交的表单数据
 * @returns {any}
 */
const getSubmitData = () => {
  let params = JSON.parse(JSON.stringify(form.value))
  //   考核人
  if (assessorUserObj.value.length > 0) {
    //考核部门
    params.assessorDept = getValueByParams(assessorUserObj.value, 'dept', 'ids')
    params.assessorDeptName = getValueByParams(
      assessorUserObj.value,
      'dept',
      'labels'
    )
    //考核职务
    params.assessorDuties = getValueByParams(
      assessorUserObj.value,
      'duties',
      'ids'
    )
    params.assessorDutiesName = getValueByParams(
      assessorUserObj.value,
      'duties',
      'labels'
    )
    //考核岗位
    params.assessorPost = getValueByParams(assessorUserObj.value, 'post', 'ids')
    params.assessorPostName = getValueByParams(
      assessorUserObj.value,
      'post',
      'labels'
    )
    //考核人员
    params.assessorUser = getValueByParams(
      assessorUserObj.value,
      'person',
      'ids'
    )
    params.assessorUserName = getValueByParams(
      assessorUserObj.value,
      'person',
      'labels'
    )
  } else {
    //考核部门
    params.assessorDept = ''
    params.assessorDeptName = ''
    //考核职务
    params.assessorDuties = ''
    params.assessorDutiesName = ''
    //考核岗位
    params.assessorPost = ''
    params.assessorPostName = ''
    //考核人员
    params.assessorUser = ''
    params.assessorUserName = ''
  }
  //   被考核人
  if (appraiserUserObj.value.length > 0) {
    //考核部门
    params.appraiseeDept = getValueByParams(
      appraiserUserObj.value,
      'dept',
      'ids'
    )
    params.appraiseeDeptName = getValueByParams(
      appraiserUserObj.value,
      'dept',
      'labels'
    )
    //考核职务
    params.appraiseeDuties = getValueByParams(
      appraiserUserObj.value,
      'duties',
      'ids'
    )
    params.appraiseeDutiesName = getValueByParams(
      appraiserUserObj.value,
      'duties',
      'labels'
    )
    //考核岗位
    params.appraiseePost = getValueByParams(
      appraiserUserObj.value,
      'post',
      'ids'
    )
    params.appraiseePostName = getValueByParams(
      appraiserUserObj.value,
      'post',
      'labels'
    )
    //考核人员
    params.appraiseeUser = getValueByParams(
      appraiserUserObj.value,
      'person',
      'ids'
    )
    params.appraiseeUserName = getValueByParams(
      appraiserUserObj.value,
      'person',
      'labels'
    )
  } else {
    //考核部门
    params.appraiseeDept = ''
    params.appraiseeDeptName = ''
    //考核职务
    params.appraiseeDuties = ''
    params.appraiseeDutiesName = ''
    //考核岗位
    params.appraiseePost = ''
    params.appraiseePostName = ''
    //考核人员
    params.appraiseeUser = ''
    params.appraiseeUserName = ''
  }

  return params
}

// 弹窗保存事件
const handleIndicatorSave = () => {
  const { validate } = proxy.$refs.formRef
  validate(valid => {
    if (valid) {
      let params = getSubmitData()
      params.orgId = userStore.user.orgId
      params.deptId = userStore.user.dept.deptId
      if (params.scoreMethod == '2' && params.targetValue == '') {
        proxy.$modal.msgWarning('请填写指标值！')
        return
      }
      if (
        params.score != '加分项' &&
        params.score != '加/减分项' &&
        params.score != '减分项'
      ) {
        if (isNaN(params.score * 1)) {
          proxy.$modal.msgWarning('分值权重必须为数字！')
          return
        }
      }

      saveBizofficeconfInfo(params).then(res => {
        if (res.code === 200) {
          proxy.$message.success(res.msg)
          emits('dialogClose')
        }
      })
    }
  })
}

const dialogClose = () => {
  emits('dialogClose')
}

/**
 * 初始化
 */
const init = () => {
  // 获取部门列表数据
  getDeptList()
  //   获取岗位数据
  getPostData()
}

init()
</script>

<style scoped lang="scss"></style>
